package com.itheima.自习.第一次.第二十三题;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;

//某公司发放年终礼品，但hr在统计的时候发现有很多同姓名同年龄的员工，
// 所以决定对这一部分员工，发放【缘分大礼包】，
// 其余员工发放【普通大礼包】，请用技术手段，完成礼品的分发。
public class Demo23 {
    public static void main(String[] args) {
        //创建一个集合,存储所有员工
        ArrayList<Employee> list = new ArrayList<>();
        list.add(new Employee("张三",23));
        list.add(new Employee("李四",24));
        list.add(new Employee("张三",23));
        list.add(new Employee("张三",28));
        //创建一个集合判断是否有同名同年龄的员工
        HashMap<Employee, Boolean> hm = new HashMap<>();
        list.forEach(employee -> {
            if (hm.containsKey(employee)){
                hm.put(employee,true);
            }else
                hm.put(employee,false);
        });

        list.forEach(employee ->
            System.out.println(employee.toString()+ "获得了" + (hm.get(employee)? "缘分大礼包":"普通大礼包")));
    }
}

class Employee{
    private String name;
    private int age;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Employee employee = (Employee) o;
        return age == employee.age &&
                Objects.equals(name, employee.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    public Employee() {
    }

    public Employee(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

